/**
 * 电影详情页面
 * 尹广超
 */

 var filmDetail={

    // 获取数据
    getDetail:function(filmId){
        var url='http://huruqing.cn:3000/api/film/getDetail';
        var self=this;
        $.ajax({
            type:'get',
            url:url,
            data:{
                filmId:filmId
            },
            dataType:'JSON',
            success:function(res){
                console.log(res);
                if(res.code==='666'){
                    
                    self.renderFilm(res.film)
                }else{
                    alert(res.msg);
                }
            }
        })
    },

    renderFilm(film){
        var self=this;
        var str=` <div class="nav abs ">
                        <img id="xianqin" src="${film.poster}" alt="">
                        <a href="./alt.html" class="iconfont abs">&#xe7dd;</a>
                        <i class="iconfont abs">&#xe7dd;</i>
                    </div>
                    <div class="ctn abs">
                        <div class="cdf jsc-sb flex">
                            <p class="ml-10 mt-10 f18 ">${film.name} <span class="sp f12 txt-c">${film.filmType}</span></p>
                            <p class="ps mr-10 mt-10 f16 ">${film.grade}<span class="f12">分</span></p>
                        </div>
                        <div class="abc f14">
                            <p class="pb-10">${film.category}</p>
                            <p class="pb-5">2019-02-05上映</p>       
                            <p class="pb-15">${film.nation} | ${film.runtime}</p>
                            <p class="se">${film.synopsis}</p>
                        </div>
                    </div>
                    <div class="cc abs">

                    </div>`;
            document.querySelector('#img').innerHTML=str;    
            self.renderActor(film.actors)
    },
    renderActor(list){
        var actorStr='';
        list.forEach(function(itme){
            actorStr+=`<div class="one ml-10">
                            <img  src="${itme.avatarAddress}" alt="">
                            <p class="txt-c f12">${itme.name}</p>
                            <p class="mm txt-c f12 mt-5">${itme.role}</p>
                        </div>`
        })
        document.querySelector('#ppa').innerHTML=actorStr;
    }
 }



var str=location.search;
var aaa=str.replace(/^\?filmId=(.*)/,'$1');
filmDetail.getDetail(aaa);

